/**
 * @FileName: MemberWhite.java
 * @Author
 * @Description:
 * @Date 2016年3月31日 下午3:13:47
 * @CopyRight ZTE Corporation
 */
package cn.hpclub.server.model;

import com.jfinal.ext.plugin.tablebind.TableBind;
import com.jfinal.plugin.activerecord.Model;

@TableBind(tableName = "member_white_list")
public class MemberWhite extends Model<MemberWhite>{

    private static final long       serialVersionUID = 2870953632757633145L;
    public static final MemberWhite dao              = new MemberWhite();

    public static final String      USERNAME         = "username";
    public static final String      CMCC_USER        = "cmcc_user";
    public static final String      REMARK           = "remark";
    public static final String      ENABLED          = "enabled";

    public MemberWhite getMemberWhiteRecord(String username){
        String sql = "select * from member_white_list where username=?";
        return dao.findFirst(sql, username);
    }

    public MemberWhite getMemberWhite(String username){
        String sql = "select * from member_white_list where username=? and enabled=1";
        return dao.findFirst(sql, username);
    }

    public String getCmccUserIfExistInWhiteList(String username){
        String sql = "select * from member_white_list where username=? and enabled=1";
        MemberWhite member = dao.findFirst(sql, username);
        if(member != null){
            return member.getStr(CMCC_USER) == null ? null : member.getStr(CMCC_USER);
        }
        return null;
    }

    public boolean existInWhiteList(String username){
        String sql = "select * from member_white_list where username=? and enabled=1";
        MemberWhite member = dao.findFirst(sql, username);
        if(member != null){
            return true;
        }
        return false;
    }

}
